package com.example.threemoni.service.impl;

import com.example.threemoni.mapper.GoodsMapper;
import com.example.threemoni.pojo.Goods;
import com.example.threemoni.pojo.Type;
import com.example.threemoni.pojo.vo.GoodsVo;
import com.example.threemoni.service.IGoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/10/25
 * @Version 1.0
 **/
@Service
public class GoodsService implements IGoodsService {
    @Resource
    private GoodsMapper goodsMapper;

    @Override
    public PageInfo<GoodsVo> findGoods(Integer offset,Integer pagesize,Integer tid) {
        PageHelper.startPage(offset,pagesize);
        return new PageInfo<>(this.goodsMapper.findGoods(tid));
    }

    @Override
    public int addGoods(Goods goods) {
        return this.goodsMapper.addGoods(goods);
    }

    @Override
    public List<Type> types() {
        return this.goodsMapper.findTypes();
    }

    @Override
    public boolean save(Goods goods) {
        return this.goodsMapper.addGoods(goods) == 1;
    }

    @Override
    public boolean hasName(String gname) {
        return this.goodsMapper.hasName(gname) == 0 ;
    }

    @Override
    public boolean delete(String ids) {
        String[] split = ids.split(",");
        return this.goodsMapper.delete(split) >= 1;
    }
}
